<template>
  <div class="goodbad-content">
    <van-tabs v-model="active" color="#ff9910" @click="onClick">
      <van-tab title="奖励"></van-tab>
      <van-tab title="处罚"></van-tab>
    </van-tabs>
    <van-cell-group>
      <van-cell
        :title="item.logDesc"
        :value="item.addtime"
        v-for="(item,index) in items"
        :key="index"
      />
    </van-cell-group>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      finished: false,
      active: 0,
      items: []
    };
  },
  beforeCreate: function() {
    //创建前
  },
  created: function() {
    //创建后
    this.Suk_getgoodlist();
  },
  beforeMount: function() {
    //挂载前
  },
  mounted: function() {
    //挂载后
  },
  beforeUpdate: function() {
    //更新前
  },
  update: function() {
    //更新后
  },
  methods: {
    onClick(index, title) {
      if(index == 0){
          this.Suk_getgoodlist()
      }else if(index == 1){
          this.Suk_getbadlist()
      }
    },
    Suk_getgoodlist() {
      let that = this;
      that.$toast.loading({
        message: "加载中..."
      });
      var Sukdata = {
        userId: localStorage.getItem("userid")
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/log/addAward", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
              that.items = res.data.data.list;
              that.$toast.clear();
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    },
    Suk_getbadlist() {
      let that = this;
      that.$toast.loading({
        message: "加载中..."
      });
      var Sukdata = {
        userId: localStorage.getItem("userid")
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/log/addPunishment", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
              console.log(res.data.data.list);
              that.items = res.data.data.list;
              that.$toast.clear();
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.goodbad-content {
  font-size: 0.3rem;
}
</style>
